﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using WPFExcelReport.Controls;
using log4net;
namespace WPFExcelReport.Helpers
{
    public static partial class Helper
    {
        public static void RotateImage(Button btn)
        {
            ImageBrush brush = btn.Background as ImageBrush; 
            var transform = Matrix.Identity;
            transform.RotateAt(180, 0.5, 0.5);
            transform.ScaleAt(-1, 1, 0.5, 0.5); 
            brush.RelativeTransform = new MatrixTransform(transform);
        }
    }
    
    public static partial class Helper
    {

        public static object CreateMachineGrid(string prefix, string machine, ref Grid am, string msbez, string start, string end, double GDays,
            double density, bool IsShowGrid = false, bool IsShowDate = false)
        {
            Grid grid = new Grid();
            if (IsShowGrid)
            {
                grid.ShowGridLines = true;
            }
            grid.Tag = prefix + machine;
            grid.Background = Brushes.LightGray;
            Thickness thick = new Thickness(0, 2, 0, 0);
            grid.Margin = thick;
            ColumnDefinition cd;
            RowDefinition rd;
            rd = new RowDefinition();
            rd.Height = new GridLength(30);
            grid.RowDefinitions.Add(rd);
            rd = new RowDefinition();
            rd.Height = new GridLength(20);
            grid.RowDefinitions.Add(rd);
            rd = new RowDefinition();
            rd.Height = new GridLength(20);
            grid.RowDefinitions.Add(rd);
            cd = new ColumnDefinition();
            cd.Width = new GridLength(10);
            grid.ColumnDefinitions.Add(cd);
            am = NewMachine(prefix, machine, msbez);
            grid.Children.Add(am);
            double gridperday = 60 / density;
            for (int i = 1; i <= GDays; i++)
            {
                for (int j = 0; j < Math.Round(24 * gridperday); j++)
                {
                    cd = new ColumnDefinition();
                    cd.Width = new GridLength(30);
                    grid.ColumnDefinitions.Add(cd);
                }
                if (IsShowDate)
                {
                }
            }
            return grid;
        }
        private static Grid NewMachine(string prefix, string machine, string msbez)
        {
            Grid grid = new Grid();
            grid.Tag = prefix + "x" + machine;
            grid.SetValue(Grid.RowProperty, 0);
            grid.SetValue(Grid.RowSpanProperty, 3);
            grid.SetValue(Grid.ColumnProperty, 0);
            return grid;
            //<GridSplitter Grid.Column="3" Width="2" Background="#FF1B1919" />
            ColumnDefinition cd;
            RowDefinition rd;
            rd = new RowDefinition();
            rd.Height = new GridLength(30);
            grid.RowDefinitions.Add(rd);
            rd = new RowDefinition();
            rd.Height = new GridLength(2);
            grid.RowDefinitions.Add(rd);
            rd = new RowDefinition();
            rd.Height = new GridLength(30);
            grid.RowDefinitions.Add(rd);
            #region====名称========
            TextBlock tx = new TextBlock();
            tx.Text = machine;
            tx.Width = 80;
            tx.VerticalAlignment = VerticalAlignment.Center;
            tx.SetValue(Grid.RowProperty, 0);
            grid.Children.Add(tx);
            #endregion
            #region====分割线========
            GridSplitter splitter = new GridSplitter();
            splitter.Height = 10;
            splitter.Width = 100;
            splitter.Background = Brushes.Black;
            splitter.SetValue(Grid.RowProperty, 1);
            grid.Children.Add(splitter);
            #endregion
            #region====描述========
            tx = new TextBlock();
            tx.Text = msbez.Replace("染色高压锅", "");
            tx.Width = 80;
            tx.SetValue(Grid.RowProperty, 2);
            tx.VerticalAlignment = VerticalAlignment.Center;
            grid.Children.Add(tx);
            #endregion
            return grid;
        }
        public static object GetJobFace(string jobid, string jobname, string art, string color, string qty, string jprefix)
        {

            Grid grid = new Grid();
            //grid.ShowGridLines = true;
            grid.Tag = jprefix + jobid;
            grid.Name = (string)grid.Tag;
            grid.Background = Brushes.White;
            Thickness thick = new Thickness(0, 0, 0, 0);
            grid.Margin = thick;
            ColumnDefinition cd;
            RowDefinition rd;
            rd = new RowDefinition();
            rd.Height = new GridLength(1, GridUnitType.Star);
            grid.RowDefinitions.Add(rd);
            rd = new RowDefinition();
            rd.Height = new GridLength(1, GridUnitType.Star);
            grid.RowDefinitions.Add(rd);
            cd = new ColumnDefinition();
            cd.Width = new GridLength(200);
            grid.ColumnDefinitions.Add(cd);
            TextBlock tx = new TextBlock();
            tx.Text = art.Trim() + "-" + color.Trim();
            tx.SetValue(Grid.RowProperty, 0);
            grid.Children.Add(tx);
            tx = new TextBlock();
            tx.Text = jobname;
            tx.SetValue(Grid.RowProperty, 1);
            grid.Children.Add(tx);
            return grid;
        }
        public static string GetMachineID(string krs, string lfd, string pos)
        {
            string machineid = "";
            /*
            if (krs.ToString() == "  ")
            {
                machineid = Helpers.Helper.GetSubRollNum(lfd) + "_" + Helpers.Helper.GetSubRollNum(pos);
            }
            else
            {
                machineid = krs.Trim() + "_" + lfd + "_" +pos;
            }*/
            machineid = krs.Trim() + "_" + lfd + "_" + pos;
            return machineid;
        }
        public static System.Drawing.Image GetImage(string fileName)
        {
            System.Drawing.Image tmpImage = null;
            System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            tmpImage = System.Drawing.Image.FromStream(fs);
            fs.Close();
            return tmpImage;
        }
    }
}